/**   
* @Title: ClientMain.java
* @Package com.an.nettyl
* @Description: TODO(用一句话描述该文件做什么)
* @author antch,861710865@qq.com   
* @date 2017年8月3日 上午9:09:44
* @version V1.0   
*/

package com.an.nettyl;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;

/**
 * @ClassName: ClientMain
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author antch,861710865@qq.com
 * @date 2017年8月3日 上午9:09:44
 * 
 */

public class ClientMain {

	/**
	 * @Title: main @Description: TODO(这里用一句话描述这个方法的作用) @param @param args
	 *         设定文件 @return void 返回类型 @throws
	 */

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		EventLoopGroup group = new NioEventLoopGroup();

		try {
			Bootstrap b = new Bootstrap();
			b.group(group).channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() {
				@Override
				public void initChannel(SocketChannel ch) throws Exception {
					ChannelPipeline p = ch.pipeline();
					p.addLast(new ClientHandler());

				}
			});
			
//			b.

			// Start the client.
			ChannelFuture f = b.connect("127.0.0.1", 8867).sync();
			
			// Wait until the connection is closed.
			f.channel().closeFuture().sync();

		} catch (InterruptedException e) {
			e.printStackTrace();
		} finally {
			// Shut down the event loop to terminate all threads.
			group.shutdownGracefully();
		}
	}

}
